var e = require;
var o = module;
var t,
    n = (t = e("DJWord")) && t.__esModule ? t : {default: t};
cc.Class({
    extends: cc.Component,
    properties: {djWord: n.default, labTitle: cc.Label, disjointed: cc.Node, pbTian: cc.Prefab},
    onDestroy: function onDestroy() {
        this.winTimeout && clearTimeout(this.winTimeout);
    },
    start: function start() {
        var e = this;
        this.level = lGlobal.curLevel;
        var o = lGlobal.lvCfg.json[lGlobal.curModel][lGlobal.curLevel],
            t = lGlobal.modelBundles[lGlobal.curModel];
        if (t) {
            var i = o.lv;
            t.load("data/" + i + "/DJWord", cc.Prefab, function (o, t) {
                if (o) console.log(o);
                else {
                    var i = cc.instantiate(t);
                    (i.parent = e.node),
                        (e.djWord = i.getComponent(n.default)),
                        (e.totalFinded = []),
                        (e.needFinded = []);
                    for (var r = 0; r < e.djWord.compose._children.length; r++) {
                        var l = e.djWord.compose._children[r].name.split("=")[1];
                        e.needFinded.indexOf(l) < 0 && e.needFinded.push(l);
                    }
                    e.labTitle.string = cc.js.formatStr(
                        "找到%d/%d个不同的字",
                        e.totalFinded.length,
                        e.needFinded.length
                    );
                    for (var c = 0; c < e.needFinded.length; c++) {
                        cc.instantiate(e.pbTian).parent = e.disjointed;
                    }
                }
            });
        }
    },
    onSubmitClick: function onSubmitClick() {
        var e = this;
        if (this.djWord) {
            var o = this.djWord.checkAnswer();
            if (o && o.a) {
                if (this.totalFinded.indexOf(o.a) < 0) {
                    var t = this.totalFinded.length,
                        n = this.disjointed._children[t].convertToWorldSpaceAR(cc.Vec2.ZERO),
                        i = o.n.parent.convertToNodeSpaceAR(n);
                    cc.tween(o.n).to(0.5, {position: i}).start(),
                        (o.n.active = !0),
                        this.totalFinded.push(o.a),
                        (this.labTitle.string = cc.js.formatStr(
                            "找到%d/%d个不同的字",
                            this.totalFinded.length,
                            this.needFinded.length
                        )),
                        this.totalFinded.length >= this.needFinded.length &&
                            (this.winTimeout = setTimeout(function () {
                                window.ui.win({model: "DisjointWord", lv: e.level});
                            }, 1500));
                } else console.log("选择重复"), lGlobal.showLToast("已经有这个字了");
            } else console.log("选择错误");
        }
        soundMgr.playSound(soundMgr.btn);
    },
    onResetClick: function onResetClick() {
        this.djWord && this.djWord.reset(), soundMgr.playSound(soundMgr.btn);
    }
});
